﻿<%@ Page Title="" Language="C#" MasterPageFile="~/pages/master/WebList.Master" AutoEventWireup="true"
    CodeBehind="RolePermissionList.aspx.cs" Inherits="BF.Web.pages.BaseSystem.RolePermissionManagement.RolePermissionList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceJs" runat="server">
    <style type="text/css">
        .treePanlStyle
        {
            position: absolute;
            bottom: 0px;
            top: 26px;
            border: #99bbe8 1px solid;
            width: 240px;
            overflow: hidden;
            right: 0px;
            float: right;
        }
        .div_scroll
        {
            bottom: 0px;
            height: 100%;
            position: absolute;
        }
    </style>
    <script type="text/javascript" language="javascript">
        function Query() {

        }

        function Add() {
            winer.OpenWin('角色信息添加', GetUrl(this) + 'RolesManagerEdit.aspx', 480, 240, false, this);
            return false;
        }

        function Delete() {
            var values = "";
            var count = 0;
            $("input[name*='Repeater1']").each(function () {
                if (this.checked) {
                    values = this.defaultValue;
                    ++count;
                }
            });

            if (count == 0) {
                Ext.MessageBox.show({
                    title: '提示',
                    msg: '请在系统功能模块选择一项!',
                    buttons: { ok: '确  定' },
                    icon: 'ext-mb-info'
                });
                return false;
            }
            else {
                Ext.MessageBox.show({
                    title: "删除提示",
                    msg: "你确认要删除该信息吗？",
                    buttons: { yes: '确  定', no: '取 消' },
                    fn: function (result) {
                        if (result == 'yes') {
                            __doPostBack("ctl00$ContentPlaceHtml$lbtnDelete", "");
                        }
                    },
                    icon: 'ext-mb-info'
                });
                return false;


                //                return confirm("你确认要删除该信息吗？");
            }
        }

        function Update() {
            var values = "";
            var count = 0;
            $("input[name*='Repeater1']").each(function () {
                if (this.checked) {
                    values = this.defaultValue;
                    ++count;
                }
            });
            if (count != 1) {

                Ext.MessageBox.show({
                    title: '提示',
                    msg: '请选择需要编辑的数据,并且只能选择一项！',
                    buttons: { ok: '确  定' },
                    icon: 'ext-mb-info'
                });
                return false;
            }
            winer.OpenWin('角色信息修改', GetUrl(this) + 'RolesManagerEdit.aspx?skey=' + values, 480, 240, false, this);
            return false;
        }

        //关闭弹出window时，执行的事件
        function Refurbish() {
            $("#ctl00_ContentPlaceHtml_lbtnQuery")[0].click();
        }
    </script>
    <script type="text/javascript">
        function GetThis() {
            return this;
        }
        Ext.BLANK_IMAGE_URL = "/script/ext3.4/resources/images/access/tree/s.gif";

        var mytree;
        Ext.onReady(function () {
            Ext.get("<%=btnSave.ClientID%>").dom.disabled = true;

            mytree = new Ext.tree.TreePanel({
                el: "container", //应用到的html元素id
                animate: true, //以动画形式伸展,收缩子节点
                title: "系统功能模块树",
                collapsible: true,
                titleCollapse: false,
                rootVisible: false, //是否显示根节点
                autoScroll: true,
                bodyBorder: false,
                border: false,
                lines: true, //节点之间连接的横竖线
                loader: new Ext.tree.TreeLoader({
                    dataUrl: "LoadCheckBoxTreeHandler.ashx?NodeID=Null"
                })

            });
            var root = new Ext.tree.AsyncTreeNode({
                id: "root",
                text: "控制面板",
                expanded: true
            });

            mytree.on('checkchange', function (node, checked) {
                node.expand();
                node.attributes.checked = checked;
                node.eachChild(function (child) {
                    child.ui.toggleCheck(checked);
                    child.attributes.checked = checked;
                    child.fireEvent('checkchange', child, checked);
                });
                if (checked) {
                    SetParentNode(node);
                }
            }, mytree);

            mytree.setRootNode(root);
            mytree.render();
            mytree.syncSize();
            Ext.get('div_scroll_x').setWidth(Ext.getBody().dom.clientWidth - 240);
            var tmp = Ext.get('container');


            tmp.dom.onresize = function () {
                mytree.syncSize();
                Ext.get('div_scroll_x').setWidth(Ext.getBody().dom.clientWidth - 240);
            }

            Ext.override(Ext.tree.TreeNodeUI, {
                onDblClick: function (e) {
                    e.preventDefault();
                    if (this.disabled) {
                        return;
                    }
                    if (!this.animating && this.node.isExpandable) {
                        this.node.toggle();
                    }
                    this.fireEvent("dblclick", this.node, e);
                }
            });
        });

        function SetParentNode(node) {
            if (node.parentNode != null) {
                var chk = node.parentNode.getUI().checkbox;
                if (chk != null)
                    chk.checked = true;
                SetParentNode(node.parentNode);
            }
        }
    </script>
    <script type="text/javascript">

        var selectRoleID
        function OnPermission(obj) {
            if (obj.checked) {
                $("#div_scroll_x :checkbox").attr("checked", false);
                obj.checked = true;
                selectRoleID = obj.value;
                Ext.get("<%=btnSave.ClientID%>").dom.disabled = false;
                var newRoleName = obj.accessKey;
                //判断是否加载其他角色
                if (Ext.get("txtRoleName").dom.value != newRoleName) {
                    ReloadTree(newRoleName);
                }
                Ext.get("txtRoleName").dom.value = newRoleName;
            }
        }

        function OnSave() {
            //            var tmpSelectNodes = mytree.getChecked();
            var selectNodes = new Array();
            GetCheckedNodes(mytree.root.childNodes[0], selectNodes);

            var s = [];
            for (var i = 0; i < selectNodes.length; i++) {
                s.push(selectNodes[i].id)
            }
            Ext.get("<%=hidSelectNodes.ClientID%>").dom.value = s;
            Ext.get("<%=hidRoleName.ClientID%>").dom.value = Ext.get("txtRoleName").dom.value;
            return true;
        }


        function GetCheckedNodes(currentNode, selectNodes) {
            if (currentNode.ui.checkbox.checked)
                selectNodes.push(currentNode)
            if (currentNode.childNodes.length) {
                for (var i = 0; i < currentNode.childNodes.length; i++) {
                    GetCheckedNodes(currentNode.childNodes[i], selectNodes);
                }
            }
        }

        function ReloadTree(roleName) {
            var node = mytree.root;
            var tmp = encodeURI(roleName);
            node.attributes.children = false;
            mytree.loader.dataUrl = "LoadCheckBoxTreeHandler.ashx?NodeID=Null&RoleName=" + tmp;
            if (node.reload)
                node.reload();
            else {
                mytree.loader.load(node, function () {
                    node.expand(true, true);
                })
            }
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHtml" runat="server">
    <table id="tabHead" border="0" style="position: absolute; left: 0px; width: 100%;
        right: 0px;" cellpadding="0" cellspacing="0" class="listtop" align="center">
        <tr style="width: 100%">
            <td>
                <div class="btn01">
                    <div style="display: none">
                        <asp:LinkButton ID="lbtnQuery" runat="server" OnClick="lbtnQuery_Click"> <span ><img src="../../../../images/search.png" alt="" border="0" /><div class="center">查询</div></span></asp:LinkButton></div>
                    <asp:LinkButton ID="lbtnAdd" runat="server" OnClientClick="return Add();"> <span><img src="../../../../images/table_add.png" alt="" border="0" /><div class="center">
                                    新增</div></span></asp:LinkButton>
                    <asp:LinkButton ID="lbtnUpdate" OnClientClick="return Update();" runat="server"> <span><img src="../../../../images/table_edit.png" alt="" border="0" /><div class="center">
                                    修改</div></span></asp:LinkButton>
                    <asp:LinkButton ID="lbtnDelete" runat="server" OnClick="lbtnDelete_Click" OnClientClick="return Delete();"> <span><img src="../../../../images/table_delete.png" alt="" border="0" /><div class="center">删除</div></span></asp:LinkButton>
                </div>
            </td>
            <td style="width: 240px; border-left: 1px  solid #9ABBE8;">
                &nbsp;角色名称：<input id="txtRoleName" type="text" style="width: 110px" readonly="readonly" />&nbsp;<asp:Button
                    ID="btnSave" runat="server" Text="保存" OnClientClick="return OnSave();" OnClick="btnSave_Click" />
            </td>
        </tr>
    </table>
    <div id="div_scroll_x" class="div_scroll">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:HiddenField ID="hidSelectNodes" runat="server" />
                <asp:HiddenField ID="hidRoleName" runat="server" />
                <asp:Repeater ID="Repeater1" runat="server">
                    <HeaderTemplate>
                        <table id="tbList" width="100%" border="0" cellpadding="0" cellspacing="0" class="list"
                            align="center">
                            <thead>
                                <tr>
                                    <td align="center" style="width: 32px;">
                                        选择 </td>
                                    <td align="center" style="width: 100px;">
                                        角色名称 </td>
                                    <td align="center">
                                        角色描述 </td>
                                    <td align="center">
                                        创建用户 </td>
                                </tr>
                            </thead>
                            <tbody>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <tr>
                            <td align="center">
                                <input type="checkbox" name="checkbox1" id="chkKey" runat="server" accesskey='<%#Eval("RoleName")%>'
                                    value='<%#Eval("RoleID")%>' onclick="OnPermission(this);" />
                                <input type="hidden" name="RoleName" id="RoleName" runat="server" value='<%#Eval("RoleName")%>' />
                            </td>
                            <td align="left">
                                <div class="divnr-auto" title='<%#Eval("RoleName")%>'>
                                    <%#Eval("RoleName")%></div>
                            </td>
                            <td align="left">
                                <div class="divnr-auto" title='<%#Eval("Description")%>'>
                                    <%#Eval("Description")%></div>
                            </td>
                        </tr>
                    </ItemTemplate>
                    <FooterTemplate>
                        </tbody> </table>
                    </FooterTemplate>
                </asp:Repeater>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="lbtnDelete" EventName="Click" />
                <asp:AsyncPostBackTrigger ControlID="lbtnQuery" EventName="Click" />
                <asp:AsyncPostBackTrigger ControlID="btnSave" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>
    </div>
    <div id="container" class="treePanlStyle">
    </div>
</asp:Content>
